<template>
  <div class="tag-list">
    <el-tag
      v-for="tag in tagList"
      :key="tag.tagId"
      size="small"
      class="tag-item"
      @click="handleTagClick(tag)"
    >
      {{ tag.tagName }}
    </el-tag>
  </div>
</template>

<script>
export default {
  name: 'TagList',
  props: {
    tags: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      tagList: []
    }
  },
  watch: {
    tags: {
      handler(newVal) {
        this.tagList = newVal
      },
      immediate: true
    }
  },
  methods: {
    handleTagClick(tag) {
      this.$emit('tag-click', tag)
    }
  }
}
</script>

<style scoped>
.tag-list {
  line-height: 1;
}

.tag-item {
  margin: 0 5px 5px 0;
  cursor: pointer;
}

.tag-item:hover {
  opacity: 0.8;
}
</style>
